require 'test/unit'
require_relative 'State_Exercise'
class TCState < Test::Unit::TestCase
  def setup
    @p = Person.new
    assert @p
  end

  def testState
  p = @p
  assert_equal p.age, 0
  assert_instance_of Child, p.state
  for i in 1..80
    p.incr_age();
    assert_equal p.age, i
    apply = p.apply_for_buspass();
    vote = p.vote();
    conscript = p.conscript();
    med_card = p.apply_for_medical_card
    if p.state.instance_of?Teenager
      assert p.age < 18
      assert_equal apply, "Pass granted"
      assert_equal vote,"Too young to vote"
      assert_equal conscript,"Here's your gun"
      assert_equal med_card, "Not qualified for medical card"
    elsif p.state.instance_of?Child
      assert p.age < 13
      assert_equal apply, "Too young for a bus pass"
      assert_equal vote,"Too young to vote"
      assert_equal conscript,"Too young to be consripted"
      assert_equal med_card, "Qualified for medical card"
    elsif p.state.instance_of?Adult
      assert p.age >= 18 and p.age < 65
      assert_equal vote,"Vote accepted"
      assert_equal conscript,"Here's your gun"
      assert_equal med_card, "Not qualified for medical card"
    elsif p.state.instance_of?Pensioner
      assert p.age >= 65
      assert_equal apply, "Pass granted"
      assert_equal vote,"Vote accepted"
      assert_equal conscript,"Too old to be consripted"
      assert_equal med_card, "Qualified for medical card"
    end
  end
  end

  def testRandom
    p = @p
    assert_equal p.age, 0
    assert_instance_of Child, p.state
    rand = 80.times.map{0+Random.rand(81)}
    rand2  = Random.new.rand(0..80)
    rand.each do |i|

      p.set_age i
      assert_equal p.age, i
      apply = p.apply_for_buspass();
      vote = p.vote();
      conscript = p.conscript();
      med_card = p.apply_for_medical_card
      if p.state.instance_of?Teenager
        assert p.age < 18
        assert_equal apply, "Pass granted"
        assert_equal vote,"Too young to vote"
        assert_equal conscript,"Here's your gun"
        assert_equal med_card, "Not qualified for medical card"
      elsif p.state.instance_of?Child
        puts "!!!!!!!!!!!!!!!!!!!!"
        print p.age
        assert p.age < 13
        assert_equal apply, "Too young for a bus pass"
        assert_equal vote,"Too young to vote"
        assert_equal conscript,"Too young to be consripted"
        assert_equal med_card, "Qualified for medical card"
      elsif p.state.instance_of?Adult
        assert p.age >= 18 and p.age < 65
        assert_equal vote,"Vote accepted"
        assert_equal conscript,"Here's your gun"
        assert_equal med_card, "Not qualified for medical card"
      elsif p.state.instance_of?Pensioner
        assert p.age >= 65
        assert_equal apply, "Pass granted"
        assert_equal vote,"Vote accepted"
        assert_equal conscript,"Too old to be consripted"
        assert_equal med_card, "Qualified for medical card"
      end
    end
  end

end